package com.example.mapper;

import com.example.entity.Eaasy;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface EaasyMapper {

    // 根据论文ID查询论文详情
    @Select("select * from Eaasy where id = #{id}")
    Eaasy selectById(Integer id);

    // 插入论文信息
    @Insert("insert into Eaasy values (null,#{title},#{journal},#{vnumber},#{pnumber},#{level},#{authors},#{fauthor},#{cauthor},#{publish},#{impact},#{link},now())")
    void insert(Eaasy eaasy);

    // 根据论文ID动态更新论文信息
    @Update("<script> " + "update Eaasy " + "<set> " + "<if test='title != null'> " + "title = #{title}, " + "</if> " + "<if test='journal != null'> " + "journal = #{journal}, " + "</if> " + "<if test='vnumber != null'> " + "vnumber = #{vnumber}, " + "</if> " + "<if test='pnumber != null'>" + "pnumber = #{pnumber}, " + "</if>" + "<if test='level != null'> " + "level = #{level}, " + "</if> " + "<if test='authors != null'> " + "authors = #{authors}, " + "</if> " + "<if test='fauthor != null'> " + "fauthor = #{fauthor}, " + "</if> " + "<if test='cauthor != null'> " + "cauthor = #{cauthor}, " + "</if> " + "<if test='publish != null'> " + "publish = #{publish}, " + "</if> " + "<if test='impact != null'> " + "impact = #{impact}, " + "</if> " + "<if test='link != null'> " + "link = #{link} " + "</if> " + "</set>" + "where id=#{id}" + "</script>")
    void updateById(Eaasy eaasy);

    // 根据论文ID删除论文信息
    @Delete("delete from Eaasy where id= #{id}")
    void deleteById(Integer id);

    // 根据条件查询论文列表
    @Select("<script>" + "select * from Eaasy <where> "+ "<if test='id !=null'> " + "and id = #{id}"+ "</if> "+ "<if test='title !=null'> " + "and title like concat('%',#{title},'%')"+ "</if> "+ "<if test='journal !=null'> " + "and journal like concat('%',#{journal},'%')"+ "</if> "+ "</where> "+ "</script>")
    List<Eaasy> selectAll(Eaasy eaasy);
}
